package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){

        List<VehicleVO> vehicles = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(vehicles);
    }
    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("参数: {}",vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("/delet/{id}")
    public JsonResult deletVehicle(@PathVariable Long id){
        log.debug("删除: {}",id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }
    @PostMapping("/unblind/{id}")
    public JsonResult updateVehicle(@PathVariable Long id){
        log.debug("修改: {}",id);
        vehicleService.updateNull(id);
        return JsonResult.ok();
    }
    @PostMapping("/bind")
    public JsonResult bindVehicle(VehicleQuery vehicleQuery){
        log.debug("绑定车辆: {}",vehicleQuery);
        vehicleService.bindVehicle(vehicleQuery);
        return JsonResult.ok();
    }

}
